﻿@model CommunityDTO
@{
    ViewBag.Title = "编辑小区";
}

<article class="page-container">
    <form class="form form-horizontal" id="form-admin-add">
        <input type="hidden" name="id" value="@Model.Id" />
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">城市：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box" style="width:150px;">
                    @Html.DropDownList("SelectCity", (List<SelectListItem>)ViewBag.ListCitiy, new { id = "SelectCity", @class = "select", size = "1" })
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>区域：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box" style="width:150px;">
                    @Html.DropDownList("regionId", (List<SelectListItem>)ViewBag.ListRegion, new { id = "SelectRegion",  @class = "select", size = "1" })
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>小区名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.Name" placeholder="" id="name" name="name">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>地址：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.Location" placeholder="" id="location" name="location">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">交通：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.Traffic" placeholder="" id="traffic" name="traffic">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">建造年份：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" onfocus="WdatePicker({ dateFmt:'yyyy' })" value="@Model.BuiltYear" id="builtYear" name="builtYear" class="input-text Wdate" style="width:120px;">
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>

@section FooterScript
{
    <!--请在下方写此页面业务相关的脚本-->
    <script type="text/javascript" src="~/Areas/WebAdmin/FrontLib/My97DatePicker/4.8/WdatePicker.js"></script>
    <script type="text/javascript" src="~/Areas/WebAdmin/FrontLib/jquery.validation/1.14.0/jquery.validate.js"></script>
    <script type="text/javascript" src="~/Areas/WebAdmin/FrontLib/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="~/Areas/WebAdmin/FrontLib/jquery.validation/1.14.0/messages_zh.js"></script>
    <script type="text/javascript">
        //加载小区数据
        function loadRegions(cityId) {
            var $SelectRegion = $("#SelectRegion");
            $SelectRegion.empty();
            //cityId 为空
            if (cityId == "") {
                return false;
            }
            //cityId 不是数字
            if (isNaN(cityId)) {
                return false;
            }
            //非法 cityId
            if (parseInt(cityId) <= 0) {
                return false;
            }
            $.post("/WebAdmin/Community/LoadRegions", { cityId: cityId }, function (res) {
                if (res.status == "ok") {
                    for (var index in res.data) {
                        $SelectRegion.append("<option value='" + res.data[index].id + "'>" + res.data[index].name + "</option>");
                    }
                }
            });
        }
        $(function () {
            //切换城市
            $("#SelectCity").change(function () {
                loadRegions($(this).val());
            });

            $("#form-admin-add").validate({
                rules: {
                    regionId: {
                        required: true
                    },
                    name: {
                        required: true
                    },
                    location: {
                        required: true
                    },
                    builtYear: {
                        number: true
                    }
                },
                onkeyup: false,
                focusCleanup: true,
                success: "valid",
                submitHandler: function (form) {
                    $(form).ajaxSubmit({
                        type: 'POST',
                        url: "/WebAdmin/Community/Edit",
                        success: function (res) {
                            if (res.status == "ok") {
                                parent.layer.msg('修改成功!', { icon: 1, time: 1000 }, function () {
                                    parent.$('.btn-refresh').click();
                                    //parent.location.reload(); //刷新父页面
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                });
                            } else if (res.status == "redirect") {
                                location.href = res.data;
                            } else if (res.status == "error") {
                                layer.msg(res.errorMsg, { icon: 2, time: 1000 });
                            } else {
                                layer.msg("修改失败", { icon: 2, time: 1000 });
                            }
                        },
                        error: function (XmlHttpRequest, textStatus, errorThrown) {
                            layer.msg('网络出错!', { icon: 2, time: 1000 });
                        }
                    });
                }
            });
        });
    </script>
    <!--/请在上方写此页面业务相关的脚本-->
}






